package cn.iocoder.yudao.module.yyzx.service.service_object;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.yyzx.controller.admin.service_object.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.service_object.Service_objectDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.yyzx.dal.mysql.service_object.Service_objectMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.*;

/**
 * 服务对象 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class Service_objectServiceImpl implements Service_objectService {

    @Resource
    private Service_objectMapper service_objectMapper;

    @Override
    public Integer createService_object(Service_objectSaveReqVO createReqVO) {
        // 插入
        Service_objectDO service_object = BeanUtils.toBean(createReqVO, Service_objectDO.class);
        service_objectMapper.insert(service_object);
        // 返回
        return service_object.getId();
    }

    @Override
    public void updateService_object(Service_objectSaveReqVO updateReqVO) {
        // 校验存在
        validateService_objectExists(updateReqVO.getId());
        // 更新
        Service_objectDO updateObj = BeanUtils.toBean(updateReqVO, Service_objectDO.class);
        service_objectMapper.updateById(updateObj);
    }

    @Override
    public void deleteService_object(Integer id) {
        // 校验存在
        validateService_objectExists(id);
        // 删除
        service_objectMapper.deleteById(id);
    }

    private void validateService_objectExists(Integer id) {
        if (service_objectMapper.selectById(id) == null) {
            throw exception(SERVICE_OBJECT_NOT_EXISTS);
        }
    }

    @Override
    public Service_objectDO getService_object(Integer id) {
        return service_objectMapper.selectById(id);
    }

    @Override
    public PageResult<Service_objectDO> getService_objectPage(Service_objectPageReqVO pageReqVO) {
        return service_objectMapper.selectPage(pageReqVO);
    }

}